<?php echo $header; ?>

<div id="content" class="w-content">
    <div class="eachBox undepages produkter-2">
        <div class="wrap-top clearfix">
            <ul class="breakcum">
                Søg<span style="text-transform:none;"><?php echo !empty($products) ? ' - ' . $text_search : '' ?></span>
            </ul>

            <?php if(!empty($products)){ ?>
                <div class="sortPro">
                    <span><?php echo $text_sort; ?></span>
                    <select class="sort_products-1" name="sort" onchange="location = this.value">
                        <?php foreach ($sorts as $sort_item) { ?>
                            <?php if (($sort . '-' . $order) == $sort_item['value']) { ?>
                                <option value="<?php echo $sort_item['href']; ?>" selected="selected"><?php echo $sort_item['text']; ?></option>
                            <?php } else { ?>
                                <option value="<?php echo $sort_item['href']; ?>"><?php echo $sort_item['text']; ?></option>
                            <?php } ?>
                        <?php }?>
                    </select>
                </div>
            <?php } ?>
        </div><!--wrap-top-->

        <?php if(empty($products)){ ?>
            <div>Ingen produkter som opfylder dine kriterier</div>
        <?php } ?>
    </div>
    <!--eachBox undepages produkter-2-->

    <div id="product_list" class="eachBox wrap-list-prod clearfix">
        <ul id="product_loaded<?php echo $lazy_load['page'] ?>" class="listProd clearfix">
            <?php $i = 0; ?>
            <?php foreach ($products as $product) { ?>
                <li>
                    <a href="#" class="product">
                        <?php if($product['discount']){ ?>
                            <div class="sale-off"><span>-<?php echo $product['rate_discount'];?></span><span>%</span></div>
                        <?php } ?>
                        <?php $href = str_replace('&', '&amp;', $product['href']); ?>
                        <a class="prod-img" href="<?php echo $href; ?>">
                            <img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>"/>
                        </a>

                        <div class="prod-name"><p><?php echo $product['name']; ?> </p></div>
                        <div class="prod-price">
                            <?php if($product['discount']){ ?>
                                <span class="price-old"> <?php echo $product['price']; ?></span><span class="price-new"><?php echo $product['discount']; ?></span>
                            <?php }else{ ?>
                                <span class="price-normal"><?php echo $product['price']; ?></span>
                            <?php } ?>
                        </div>

                        <?php if($product['options'] & false) { ?>
                            <div class="product_sizes_popup">
                                <?php
                                $op = 0;
                                foreach($product['options'] as $options){
                                    $option_data = '';
                                    foreach($options['option_value'] as $option_item){
                                        $option_data .=  $option_item['name'] . ', ';
                                    }
                                    $option_data = trim($option_data, ', ');
                                ?>

                                    <p class="header <?php echo ($op > 0 ? ' p5t' : ''); ?>"><?php echo (strcasecmp($options['name'], 'Størrelse') == 0) ? 'Størrelser' : $options['name'] ?></p>
                                    <p class="data"><?php echo $option_data ?></p>
                                    <?php $op++; ?>
                                <?php } ?>
                            </div>
                        <?php } ?>

                        <a href="<?php echo $href; ?>" class="btn btnBestil">Bestil Nu</a>
                        <div class="see-inc"><a class="hastool" title="<?php echo $shipping_note; ?>">Se pris inkl. fragt/gebyr</a></div>
                    </a>
                </li>

                <?php $i++; ?>
            <?php } ?>
        </ul>

        <div id="lazy_loading" class="lazy_loading">
            <a id="load_next_page" href="#">
                <span>Se flere produkter</span>
                <img src="catalog/view/theme/<?php echo $template; ?>/images/lazyload14.gif"/>
            </a>
        </div>
    </div>
    <!--eachBox wrap-list-prod-->

    <?php echo $services ?>
    <?php echo newsletter ?>

    <script type="text/javascript">
        var page = <?php echo $lazy_load['page'] ?>;
        var limit = <?php echo $lazy_load['limit'] ?>;
        var total = <?php echo $lazy_load['total'] ?>;
        var url = '<?php echo $lazy_load['url']?>&lazy_load=1';

        $(window).scroll(function() {
            var pos = $(window).scrollTop();
            var windowHeight = $(window).height();
            var footer = Math.round($('#footer').offset().top);
            var loadingId = '#lazy_loading';


            $(loadingId).hide();
            if((pos + windowHeight > footer - 100) && ((page) * limit < total)){
                $(loadingId).show();
            }
        });

        $('#load_next_page').on('click', function(e){
            e.preventDefault();

            var data = {
                "page":             page,
                "limit":            limit,
                "total":            total,
                "url":              url,

                "loading_id":       'lazy_loading',
                "result_id":        'product_list ul:last'
            }

            page = lazyLoad(data);
        })
    </script>

<?php echo $footer; ?>

